<template>
  <div id="rejudge-box">
    <el-card style="margin: auto; max-width: 600px">

      <div style="text-align: center;"><h3>题目重判</h3><h4>(暂不支持多条件重判)</h4></div>
      <div class="rejudge-item">
        题目ID:
        <el-input v-model="problemId"></el-input>
        <el-button style="margin-left: 4px" @click="rejudge(3)">重测</el-button>
      </div>
      <div class="rejudge-item">
        提交ID:
        <el-input v-model="runId"></el-input>
        <el-button style="margin-left: 4px" @click="rejudge(4)">重测</el-button>
      </div>
      <div class="rejudge-item">
        考试ID:
        <el-input v-model="contestId"></el-input>
        <el-button style="margin-left: 4px" @click="rejudge(1)">重测</el-button>
      </div>
      <div class="rejudge-item">
        用户ID:
        <el-input v-model="userId"></el-input>
        <el-button style="margin-left: 4px" @click="rejudge(2)">重测</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import {reJudge} from "@/network/submission";

export default {
  name: "Rejudge",
  data() {
    return {
      problemId: '',
      runId: '',
      contestId: '',
      userId: '',
    }
  },
  methods: {
    rejudge(type) {
      let contestId = null;
      let problemId = null;
      let runId = null;
      let userId = null;
      if (type === 1) {
        if (this.contestId !== null && this.contestId !== '') {
          contestId = this.contestId;
        }
      } else if (type === 2) {
        if (this.userId !== null && this.userId !== '') {
          userId = this.userId;
        }
      } else if (type === 3) {
        if (this.problemId !== null && this.problemId !== '') {
          problemId = this.problemId;
        }
      } else if (type === 4) {
        if (this.runId !== null && this.runId !== '') {
          runId = this.runId;
        }
      }
      reJudge(contestId, userId, problemId, runId)
          .then(res => {
            this.$message.success("已提交重测");
          })
    }
  }
}
</script>

<style scoped>
#rejudge-box {
  padding: 8px;
}

.rejudge-item {
  display: flex;
  max-width: 500px;
  padding: 4px;
  margin: auto;
}
</style>